from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service


# 指定chromedriver的路径
# service = Service(executable_path='/usr/local/bin/chromedriver')
# service.start()
# driver = webdriver.Chrome(service=service)

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("file:////Users/minyang/local/work/PycharmProjects/git/learn/week34/webautotest/page/form.html")
# by id
# driver.find_element_by_id('inputEmail').click()
driver.find_element(By.ID,'inputEmail').click()
sleep(1)
# #by name
# driver.find_element_by_name('password').click()
driver.find_element(By.NAME,'password').click()
# sleep(1)
# #by tagname
# print(driver.find_element_by_tag_name('form').get_attribute('class'))
print(driver.find_element(By.TAG_NAME,'form').get_attribute('class'))
sleep(1)
# #by classname
# el = driver.find_element_by_class_name('controls')
el = driver.find_element(By.CLASS_NAME,'controls')
driver.execute_script('$(arguments[0]).fadeOut().fadeIn()',el)
# sleep(1)
#by linktext
# link = driver.find_element_by_link_text('register')
link = driver.find_element(By.LINK_TEXT,'register')
# driver.execute_script('$(arguments[0]).fadeOut().fadeIn()',link)
# sleep(2)
# partile = driver.find_element_by_partial_link_text('reg')
partile = driver.find_element(By.PARTIAL_LINK_TEXT,'reg')
# driver.execute_script('$(arguments[0]).fadeOut().fadeIn()',partile)
# sleep(3)
# by css selector
# div = driver.find_element_by_css_selector('body > form > div:nth-child(1) > div')
div = driver.find_element(By.CSS_SELECTOR,'body > form > div:nth-child(1) > div')
# driver.execute_script('$(arguments[0]).fadeOut().fadeIn()',div)
#by xpath
# 老版本
# driver.find_element_by_xpath("/html/body/form/div[3]/div/button").click()
driver.find_element(By.XPATH,'/html/body/form/div[3]/div/button')
sleep(3)

driver.quit()

